Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure instantiateMVarsProfiling adds a trace node #5501

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

alexkeizer
Copy link
Contributor

@alexkeizer alexkeizer commented Sep 27, 2024

We add a new Meta.instantiateMVars trace node to the instantiateMVarsProfiling definition used in elabMutualDef, and we replace various uses of plain instantiateMVars with the profiled version (which necessitated pulling up the definition to be higher in the file).

This fixes a "time leak" when profiling large proofs, where instantiating the goal metavariable can take a significant amount of time, that previously would not be accounted for when using the trace profiler.

This fixes a "time leak" when profiling large proofs, where instantiating the goal meta variable can take a significant amount of time.
@alexkeizer alexkeizer changed the title fix: ensure instantiateMVarsProfiling adds a trace node. fix: ensure instantiateMVarsProfiling adds a trace node Sep 27, 2024
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Sep 27, 2024
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 56b78a0ed104c896c033bcd2284449cea2dd5d12 --onto 0196bca784f82f90b4efd2a85a400daf4ab767f8. (2024-09-27 21:52:40)

@hargoniX
Copy link
Contributor

hargoniX commented Oct 7, 2024

!bench to ensure the code doesn't introduce non trivial regressions.

@hargoniX
Copy link
Contributor

hargoniX commented Oct 7, 2024

I'm also not exactly sure that this is the proper solution for the instantiateMVars time leak. This is only going to profile it in very specific situations, a more uniform solution seems more desirable to me? But also potentially more threatening to performance.

@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit e78addd.
There were significant changes against commit 56b78a0:

  Benchmark                 Metric       Change
  =======================================================
+ import Lean               task-clock   -11.4% (-12.9 σ)
+ import Lean               wall-clock   -11.5% (-12.9 σ)
+ lake config tree          task-clock    -9.3% (-17.4 σ)
+ lake config tree          wall-clock    -9.3% (-16.7 σ)
+ language server startup   task-clock    -1.8% (-13.6 σ)
+ language server startup   wall-clock    -1.8% (-10.4 σ)

@alexkeizer
Copy link
Contributor Author

alexkeizer commented Oct 7, 2024

I'm also not exactly sure that this is the proper solution for the instantiateMVars time leak. This is only going to profile it in very specific situations, a more uniform solution seems more desirable to me? But also potentially more threatening to performance.

Fair point. It should be noted that instantiateMVarsProfiling was already a thing, I just expanded its use and ensured it has a trace node so that it shows up in the trace profiler also, previously it would only show up in the other profiler.

The proper solution would be to add a trace node to instantiateMVars itself, I agree, but that is a lot trickier. Lean.Util.Trace (which defines the trace machinery) imports Lean.MetavarContext (where instantiateMVars lives), so we'd have to figure out why this is, and I suspect we'd have to split MetavarContext up.

@alexkeizer
Copy link
Contributor Author

@hargoniX, since you added thumbs-up to my last comment, does that mean you approve of the change in this PR, or do you think we should do the "proper" solution and rip up instantiateMVars to add a trace node directly?

@hargoniX
Copy link
Contributor

hargoniX commented Nov 1, 2024

I do understand why you did what you did now. But I do not have enough knowledge about our meta internals to know what exactly would be required here. Someone else from the team would have to weigh in.

@alexkeizer
Copy link
Contributor Author

awaiting-review

Probably helps if I put that tag on. I'll be away for the next two/three weeks, though, so I won't respond to any review comments until then

@github-actions github-actions bot added awaiting-review Waiting for someone to review the PR and removed awaiting-review Waiting for someone to review the PR labels Nov 1, 2024
@Kha Kha added this pull request to the merge queue Nov 8, 2024
Merged via the queue into leanprover:master with commit fc0529b Nov 8, 2024
14 of 15 checks passed
@kim-em kim-em added the changelog-language Language features, tactics, and metaprograms label Jan 4, 2025
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
…#5501)

We add a new `Meta.instantiateMVars` trace node to the
`instantiateMVarsProfiling` definition used in `elabMutualDef`, and we
replace various uses of plain `instantiateMVars` with the profiled
version (which necessitated pulling up the definition to be higher in
the file).

This fixes a "time leak" when profiling large proofs, where
instantiating the goal metavariable can take a significant amount of
time, that previously would not be accounted for when using the trace
profiler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR changelog-language Language features, tactics, and metaprograms toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants